<template>
  <div class="list">
    <van-nav-bar
      :title="xx"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    fixed/>
    <img class="newbanner" :src="newBanner" alt="" />
    <div class="banner">
      <div @click="bgc = 0" :class="{ active: bgc == 0 }">综合</div>
      <div class="price" @click="tabber">
        <div @click="bgc = 1" :class="{ active: bgc == 1 }">价格</div>
        <div class="icon">
          <van-icon name="arrow-up" :color="current == 'up' ? '#cea62a' : ''" />
          <van-icon
            name="arrow-down"
            :color="current == 'down' ? '#cea62a' : ''"
          />
        </div>
      </div>
      <div @click="bgc = 2" :class="{ active: bgc == 2 }">分类</div>
    </div>
    <ul class="goodslist">
      <li v-for="item in list" :key="item.id">
        <img :src="item.list_pic_url" alt="" />
        <p class="goodstitle">{{ item.name }}</p>
        <p class="goodsprice">￥{{ item.retail_price }}</p>
      </li>
    </ul>
  </div>
</template>

<script>
import { goodsList } from "@/api/home/list";
export default {
  data() {
    return {
      list: [],
      id: "",
      isImg: "",
      current: "default", //default up down
      bgc: 0,
      xx: "",
      newBanner: "",
    };
  },
  created() {
    var id = this.$route.query.id;
    this.id = this.$route.query.id;
    if (this.id == 1) {
      this.newBanner =
        "http://jinglins.gitee.io/bufan-tesco-mall/assets/new-list-banner-b691c95d.png";
        this.xx='新品首发'
    } else {
      this.newBanner =
        "http://jinglins.gitee.io/bufan-tesco-mall/assets/hot-list-banner-ccf22d3f.png";
        this.xx='人气推荐'
    }
    goodsList({
      isNew: id == 1 ? 1 : "",
      isHot: id == 2 ? 1 : "",
      order: "",
    }).then((res) => {
      console.log(res);
      this.list = res.data;
    });
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    tabber() {
      if (this.current == "default") {
        this.current = "up";
      } else if (this.current == "up") {
        this.current = "down";
      } else {
        this.current = "up";
      }
      goodsList({
        isNew: this.id == 1 ? 1 : "",
        isHot: this.id == 2 ? 1 : "",
        order: this.current == "up" ? "asc" : "desc",
      }).then((res) => {
        console.log(res);
        this.list = res.data;
      });
    },
    bigtab() {},
  },
};
</script>

<style lang="scss" scoped>
.list {
  background-color: #f7f7f7;
  .active {
    color: #cea62a;
  }
  .newtitle {
    text-align: center;
    background-color: #fff;
    height: 100px;
    line-height: 100px;
  }

  .banner {
    display: flex;
    justify-content: space-around;
    font-size: 28px;
    color: #212121;
    font-weight: 400;
    height: 100px;
    line-height: 100px;
    background-color: #fff;
    .price {
      position: relative;
      .icon {
        display: flex;
        flex-direction: column;
        align-items: center;
        position: absolute;
        right: -35px;
        top: 23px;
      }
    }
  }
  .newbanner {
    width: 750px;
    // height: 326px;
  }
  .goodslist {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin: 0px 20px;
    img {
      width: 350px;
      height: 350px;
      background-color: #fff;
      margin-top: 19px;
    }
    .goodstitle {
      font-size: 26px;
      color: #333333;
      letter-spacing: 0;
      font-weight: 500;
      margin: 17px 0px 0px 22px;
      width: 300px;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .goodsprice {
      font-size: 26px;
      color: #9e4242;
      letter-spacing: 0;
      font-weight: 400;
      margin: 5px 0px 44px 22px;
    }
  }
}
</style>